﻿@model CustomerModel

@if (Model.CountryEnabled && Model.StateProvinceEnabled)
{
    <script>
        $(document).ready(function() {
            $("#@Html.IdFor(model => model.CountryId)").change(function() {
                var selectedItem = $(this).val();
                var ddlStates = $("#@Html.IdFor(model => model.StateProvinceId)");

                var postData = {
                    countryId: selectedItem,
                    addSelectStateItem: "true"
                };

                $.ajax({
                    cache: false,
                    type: "GET",
                    url: "@(Url.Action("GetStatesByCountryId", "Home", new { area = Constants.AreaAdmin }))",
                    data: postData,
                    success: function(data) {
                        ddlStates.html('');
                        $.each(data, function(id, option) {
                            ddlStates.append($('<option></option>').val(option.id).html(option.name));
                        });
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
                        alert('Failed to retrieve states.');
                    }
                });
            });
        });
    </script>
}
<div class="form-horizontal">
<vc:admin-widget widget-zone="customer_details_info_top" additional-data="Model"/>
<div class="form-body">
@if (Model.UsernamesEnabled)
{
    if (string.IsNullOrEmpty(Model.Id) || Model.AllowUsersToChangeUsernames)
    {
        <div class="form-group">
            <admin-label asp-for="Username"/>
            <div class="col-md-9 col-sm-9">
                <admin-input asp-for="Username"/>
                <span asp-validation-for="Username"></span>
            </div>
        </div>
    }
    else
    {
        <div class="form-group">
            <admin-label asp-for="Username"/>
            <div class="col-md-9 col-sm-9">
                <label class="control-label"> @Model.Username</label>
                <input asp-for="Username" type="hidden"/>
            </div>
        </div>
    }
}
<div class="form-group">
    <admin-label asp-for="Email"/>
    <div class="col-md-9 col-sm-9">
        <admin-input asp-for="Email"/>
        <span asp-validation-for="Email"></span>
    </div>
</div>
<div class="form-group">
    <admin-label asp-for="Password"/>
    <div class="col-md-9 col-sm-9">
        <div class="input-group">
            <div class="input-icon">
                <i class="fa fa-lock fa-fw"></i>
                <admin-input asp-for="Password" autocomplete="off"/>
            </div>
        </div>
    </div>
</div>
<div class="form-group">
    @{
        ViewData["DisableIgnoreAclWarnings"] = true;
    }
    <admin-label asp-for="CustomerGroups"/>
    <div class="col-md-9 col-sm-9">
        <admin-input asp-for="CustomerGroups"/>
        <span asp-validation-for="CustomerGroups"></span>
    </div>
</div>
<div class="form-group">
    <admin-label asp-for="CustomerTags"/>
    <div class="col-md-9 col-sm-9">
        <admin-input asp-for="CustomerTags"/>
        <span asp-validation-for="CustomerTags"></span>
    </div>
</div>
@if (!string.IsNullOrEmpty(Model.Id) && Model.AssociatedExternalAuthRecords.Count > 0)
{
    <div class="form-group">
        <admin-label asp-for="AssociatedExternalAuthRecords"/>
        <div class="col-md-9 col-sm-9">
            <div id="externalauthrecords-grid"></div>
            <script>

                            //local datasource
                            var externalauthrecords = [
                            @for (var i = 0; i < Model.AssociatedExternalAuthRecords.Count; i++)
                            {
                                var aear = Model.AssociatedExternalAuthRecords[i];
                                <text>
                                {
                                    AuthMethodName: "@aear.AuthMethodName",
                                    Email: "@aear.Email",
                                    ExternalIdentifier: "@aear.ExternalIdentifier"
                                }
                                 </text>
                                if (i != Model.AssociatedExternalAuthRecords.Count - 1)
                                {
                                    <text>,</text>
                                }
                            }
                            ];

                            $(document).ready(function () {
                                $("#externalauthrecords-grid").kendoGrid({
                                    dataSource: {
                                        data: externalauthrecords,
                                        schema: {
                                            model: {
                                                fields: {
                                                    AuthMethodName: { type: "string" },
                                                    Email: { type: "string" },
                                                    ExternalIdentifier: { type: "string" }
                                                }
                                            }
                                        },
                                        error: function (e) {
                                            display_kendoui_grid_error(e);
                                            // Cancel the changes
                                            this.cancelChanges();
                                        }
                                    },
                                    pageable: {
                                        refresh: true,
                                        numeric: false,
                                        previousNext: false,
                                        info: false
                                    },
                                    scrollable: false,
                                    columns: [
                                        {
                                            field: "AuthMethodName",
                                            title: "@Loc["Admin.Customers.Customers.AssociatedExternalAuth.Fields.AuthMethodName"]",
                                            width: 100
                                        }, {
                                            field: "Email",
                                            title: "@Loc["Admin.Customers.Customers.AssociatedExternalAuth.Fields.Email"]",
                                            width: 100
                                        },{
                                            field: "ExternalIdentifier",
                                            title: "@Loc["Admin.Customers.Customers.AssociatedExternalAuth.Fields.ExternalIdentifier"]",
                                            width: 300
                                        }
                                    ]
                                });
                            });

                        </script>
        </div>
    </div>
}
<div class="form-group">
    <admin-label asp-for="VendorId"/>
    <div class="col-md-9 col-sm-9">
        <admin-input asp-for="VendorId"/>
        <span asp-validation-for="VendorId"></span>
        <em>@Loc["Admin.Customers.Customers.VendorShouldBeInVendorsGroup"]</em>
    </div>
</div>
<div class="form-group">
    <admin-label asp-for="StaffStoreId"/>
    <div class="col-md-9 col-sm-9">
        <admin-select asp-for="StaffStoreId" asp-items="Model.AvailableStores"/>
        <span asp-validation-for="StaffStoreId"></span>
    </div>
</div>
<div class="form-group">
    <admin-label asp-for="Owner"/>
    <div class="col-md-9 col-sm-9">
        <admin-input asp-for="Owner"/>
        <span asp-validation-for="Owner"></span>
    </div>
</div>
<div class="form-group">
    <admin-label asp-for="SeId"/>
    <div class="col-md-9 col-sm-9">
        <admin-select asp-for="SeId" asp-items="Model.AvailableSalesEmployees"/>
        <span asp-validation-for="SeId"></span>
    </div>
</div>
@if (Model.GenderEnabled)
{
    <div class="form-group">
        <admin-label asp-for="Gender"/>
        <div class="col-md-9 col-sm-9">
            <div class="gender">
                @Html.RadioButton("Gender", "M", Model.Gender == "M", new { id = "Gender_Male" })
                <label class="forcheckbox" for="Gender_Male">@Loc["Admin.Customers.Customers.Fields.Gender.Male"]</label>
            </div>
            <div class="gender">
                @Html.RadioButton("Gender", "F", Model.Gender == "F", new { id = "Gender_Female" })
                <label class="forcheckbox" for="Gender_Female">@Loc["Admin.Customers.Customers.Fields.Gender.Female"]</label>
            </div>
        </div>
    </div>
}
<div class="form-group">
    <admin-label asp-for="FirstName"/>
    <div class="col-md-9 col-sm-9">
        <admin-input asp-for="FirstName"/>
        <span asp-validation-for="FirstName"></span>
    </div>
</div>
<div class="form-group">
    <admin-label asp-for="LastName"/>
    <div class="col-md-9 col-sm-9">
        <admin-input asp-for="LastName"/>
        <span asp-validation-for="LastName"></span>
    </div>
</div>
@if (Model.DateOfBirthEnabled)
{
    <div class="form-group">
        <admin-label asp-for="DateOfBirth"/>
        <div class="col-md-9 col-sm-9">
            <admin-input asp-for="DateOfBirth"/>
            <span asp-validation-for="DateOfBirth"></span>
        </div>
    </div>
}
@if (Model.CompanyEnabled)
{
    <div class="form-group">
        <admin-label asp-for="Company"/>
        <div class="col-md-9 col-sm-9">
            <admin-input asp-for="Company"/>
            <span asp-validation-for="Company"></span>
        </div>
    </div>
}
@if (Model.StreetAddressEnabled)
{
    <div class="form-group">
        <admin-label asp-for="StreetAddress"/>
        <div class="col-md-9 col-sm-9">
            <admin-input asp-for="StreetAddress"/>
            <span asp-validation-for="StreetAddress"></span>
        </div>
    </div>
}
@if (Model.StreetAddress2Enabled)
{
    <div class="form-group">
        <admin-label asp-for="StreetAddress2"/>
        <div class="col-md-9 col-sm-9">
            <admin-input asp-for="StreetAddress2"/>
            <span asp-validation-for="StreetAddress2"></span>
        </div>
    </div>
}
@if (Model.ZipPostalCodeEnabled)
{
    <div class="form-group">
        <admin-label asp-for="ZipPostalCode"/>
        <div class="col-md-9 col-sm-9">
            <admin-input asp-for="ZipPostalCode"/>
            <span asp-validation-for="ZipPostalCode"></span>
        </div>
    </div>
}
@if (Model.CityEnabled)
{
    <div class="form-group">
        <admin-label asp-for="City"/>
        <div class="col-md-9 col-sm-9">
            <admin-input asp-for="City"/>
            <span asp-validation-for="City"></span>
        </div>
    </div>
}
@if (Model.CountryEnabled)
{
    <div class="form-group">
        <admin-label asp-for="CountryId"/>
        <div class="col-md-9 col-sm-9">
            <admin-select asp-for="CountryId" asp-items="Model.AvailableCountries"/>
            <span asp-validation-for="CountryId"></span>
        </div>
    </div>
}
@if (Model.CountryEnabled && Model.StateProvinceEnabled)
{
    <div class="form-group">
        <admin-label asp-for="StateProvinceId"/>
        <div class="col-md-9 col-sm-9">
            <admin-select asp-for="StateProvinceId" asp-items="Model.AvailableStates"/>
            <span asp-validation-for="StateProvinceId"></span>
        </div>
    </div>
}
@if (Model.PhoneEnabled)
{
    <div class="form-group">
        <admin-label asp-for="Phone"/>
        <div class="col-md-9 col-sm-9">
            <admin-input asp-for="Phone"/>
            <span asp-validation-for="Phone"></span>
        </div>
    </div>
}
@if (Model.FaxEnabled)
{
    <div class="form-group">
        <admin-label asp-for="Fax"/>
        <div class="col-md-9 col-sm-9">
            <admin-input asp-for="Fax"/>
            <span asp-validation-for="Fax"></span>
        </div>
    </div>
}
@if (Model.CustomerAttributes.Count > 0)
{
    <div class="form-group">
        <partial name="Partials/CustomerAttributes" model="Model.CustomerAttributes"/>
    </div>
}
<div class="form-group">
    <admin-label asp-for="AdminComment"/>
    <div class="col-md-9 col-sm-9">
        <admin-textarea asp-for="AdminComment"></admin-textarea>
        <span asp-validation-for="AdminComment"></span>
    </div>
</div>
<div class="form-group">
    <admin-label asp-for="IsTaxExempt"/>
    <div class="col-md-9 col-sm-9">
        <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
            <admin-input asp-for="IsTaxExempt"/>
            <div class="control__indicator"></div>
        </label>
        <span asp-validation-for="IsTaxExempt"></span>
    </div>
</div>
<div class="form-group">
    <admin-label asp-for="FreeShipping"/>
    <div class="col-md-9 col-sm-9">
        <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
            <admin-input asp-for="FreeShipping"/>
            <div class="control__indicator"></div>
        </label>
        <span asp-validation-for="FreeShipping"></span>
    </div>
</div>
<div class="form-group">
    <admin-label asp-for="TwoFactorEnabled"/>
    <div class="col-md-9 col-sm-9">
        <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
            <admin-input asp-for="TwoFactorEnabled"/>
            <div class="control__indicator"></div>
        </label>
        <span asp-validation-for="TwoFactorEnabled"></span>
    </div>
</div>
@if (!string.IsNullOrEmpty(Model.AffiliateId))
{
    <div class="form-group">
        <admin-label asp-for="AffiliateId"/>
        <div class="col-md-9 col-sm-9">
            <a class="k-button" href="@Url.Action("Edit", "Affiliate", new { id = Model.AffiliateId, area = Constants.AreaAdmin })"><span class="k-icon k-i-eye"></span>&nbsp;@Model.AffiliateName - @Loc["Admin.Common.View"]</a>
            <button type="submit" name="remove-affiliate" asp-action="RemoveAffiliate" class="k-button red"><span class="k-icon k-i-delete"></span>&nbsp;@Loc["Admin.Customers.Customers.Fields.Affiliate.Remove"]</button>
        </div>
    </div>
}
@if (Model.DisplayVatNumber)
{
    <div class="form-group">
        <admin-label asp-for="VatNumber"/>
        <div class="col-md-9 col-sm-9">
            <div class="input-group-control">
                <admin-input asp-for="VatNumber"/>
                <label class="control-label">
                    (@string.Format(Loc["Admin.Customers.Customers.Fields.VatNumberStatus"], Model.VatNumberStatusNote))
                </label>
                <input type="submit" name="markVatNumberAsValid" asp-action="MarkVatNumberAsValid" class="btn green" value="@Loc["Admin.Customers.Customers.Fields.VatNumber.MarkAsValid"]"/>
                <input type="submit" name="markVatNumberAsInvalid" asp-action="MarkVatNumberAsInvalid" class="btn red" value="@Loc["Admin.Customers.Customers.Fields.VatNumber.MarkAsInvalid"]"/>
            </div>
            <span asp-validation-for="VatNumber"></span>
        </div>
    </div>
}
@if (Model.AvailableNewsletterSubscriptionStores is { Count: > 0 })
{
    <div class="form-group">
        <admin-label asp-for="SelectedNewsletterSubscriptionStoreIds"/>
        <div class="col-md-9 col-sm-9">
            @foreach (var store in Model.AvailableNewsletterSubscriptionStores)
            {
                <div>
                    <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
                        <input type="checkbox" name="SelectedNewsletterSubscriptionStoreIds" value="@store.Id" checked="@(Model.SelectedNewsletterSubscriptionStoreIds != null && Model.SelectedNewsletterSubscriptionStoreIds.Contains(store.Id))"/>(@(store.Name))
                        <div class="control__indicator"></div>
                    </label>

                </div>
            }
        </div>
    </div>
}
else
{
    <div class="note note-info">
        @Loc["Admin.Customers.Customers.Fields.CustomerGroups.NoGroups"]
    </div>
}
<div class="form-group">
    <admin-label asp-for="Active"/>
    <div class="col-md-9 col-sm-9">
        <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
            <admin-input asp-for="Active"/>
            <div class="control__indicator"></div>
        </label>
        <span asp-validation-for="Active"></span>
    </div>
</div>
@if (!string.IsNullOrEmpty(Model.Id))
{
    <div class="form-group">
        <admin-label asp-for="LastIpAddress"/>
        <div class="col-md-9 col-sm-9">
            <label class="control-label">@Model.LastIpAddress</label>
        </div>
    </div>
}
@if (!string.IsNullOrEmpty(Model.Id))
{
    <div class="form-group">
        <admin-label asp-for="CreatedOn"/>
        <div class="col-md-9 col-sm-9">
            <label class="control-label">@Model.CreatedOn</label>
        </div>
    </div>
}
@if (!string.IsNullOrEmpty(Model.Id))
{
    <div class="form-group">
        <admin-label asp-for="LastActivityDate"/>
        <div class="col-md-9 col-sm-9">
            <label class="control-label">@Model.LastActivityDate</label>
        </div>
    </div>
}
@if (!string.IsNullOrEmpty(Model.Id) && !string.IsNullOrEmpty(Model.LastVisitedPage))
{
    <div class="form-group">
        <admin-label asp-for="LastVisitedPage"/>
        <div class="col-md-9 col-sm-9">
            <label class="control-label">@Model.LastVisitedPage</label>
        </div>
    </div>
}
@if (!string.IsNullOrEmpty(Model.Id) && Model.LastPurchaseDate.HasValue)
{
    <div class="form-group">
        <admin-label asp-for="LastPurchaseDate"/>
        <div class="col-md-9 col-sm-9">
            <label class="control-label">@Model.LastPurchaseDate</label>
        </div>
    </div>
}
</div>
<vc:admin-widget widget-zone="customer_details_info_bottom" additional-data="Model"/>
</div>